<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function dump($var, $return = false, $hsp = false) {
	if ($return == true) {
		$html = "<pre>";
		$html .= var_export($var, $return);
		$html .= "</pre>";
		return $html;
	} else {
		echo "<pre class='dumping'>";
		if (!$hsp) {
			var_dump($var);
		} else {
			foreach ($var as $k => $v) {
				echo "'".$k."' => '".htmlspecialchars(str_replace("\r\n", "", $v))."'\r\n";
			}
		}
		echo "</pre>";
	}
}

function showmeactions($page, $id, $status, $edit, $delete, $stat, $from) {
	if ($from != "" AND is_numeric($from)) $pgng = "?from=".intval($from);
	$html .= "<div class='admin_actions'>";
	if ($stat == 1) {
		if ($status == 1) {
			$html .= "<a href='/admin/".$page."/block/".$id."/".$pgng."'>";
				$html .= "<img src='/data/images/icons/block.png' alt='Заблокировать/Скрыть запись' title='Заблокировать/Скрыть запись' />";
			$html .= "</a>";
		} else {
			$html .= "<a href='/admin/".$page."/unblock/".$id."/".$pgng."'>";
				$html .= "<img src='/data/images/icons/unblock.png' alt='Разблокировать/Показать запись' title='Разблокировать/Показать запись' />";
			$html .= "</a>";
		}
	}
	if ($edit == 1) {
		$html .= "<a href='/admin/".$page."/edit/".$id."/'>";
			$html .= "<img src='/data/images/icons/edit.png' alt='Редактировать запись' title='Редактировать запись' />";
		$html .= "</a>";
	}
	if ($delete == 1) {
		$html .= "<a href='/admin/".$page."/delete/".$id."/".$pgng."' class='with_confirm'>";
			$html .= "<img src='/data/images/icons/delete.png' alt='Удалить запись' title='Удалить запись' />";
		$html .= "</a>";
	}
	$html .= "</div>";
	return $html;
}
function showmeadd($page, $text, $type = "", $active_parent = "") {
	$html .= "<a href='/admin/".$page."/add/".($type!=""?$type.'/':'').$active_parent."' class='add_action fr'>";
		$html .= "<img src='/data/images/icons/add.png' alt='".$text."' title='".$text."' />";
		$html .= $text;
	$html .= "</a>";
	return $html;
}
function showmesplash($text, $type = 'error') {
	if ($text != "") {
		$html = "<div class='splash type_".$type." br-10'>";
		$html .= "<h3>".($type=="error"?"Ошибка":"Внимание")."</h3>";
			$html .= $text;
		$html .= "</div>";
		echo $html;
	} else {
		return true;
	}
}
function to5zeros($var) {
	$numbers = strlen($var);
	$need = 5 - $numbers;
	$return = "";
	while ($i < $need) {
		$return .= "0";
		$i++;
	}
	$return .= $var;
	return $return;
}
function showmedate($var) {
	return date("d.m.Y", $var);
}
function showmenotice($text) {
		$html = "<div class='notice'>";
		$html .= "<h3>Внимание</h3>";
			$html .= $text;
		$html .= "</div>";
		return $html;
}
 function parse_youtube_url($url,$return='embed',$width='',$height='',$rel=0){
    $urls = parse_url($url);

    //expect url is http://youtu.be/abcd, where abcd is video iD
    if($urls['host'] == 'youtu.be'){
        $id = ltrim($urls['path'],'/');
    }
    //expect  url is http://www.youtube.com/embed/abcd
    else if(strpos($urls['path'],'embed') == 1){
        $id = end(explode('/',$urls['path']));
    }
     //expect url is abcd only
    else if(strpos($url,'/')===false){
        $id = $url;
    }
    //expect url is http://www.youtube.com/watch?v=abcd
    else{
        parse_str($urls['query']);
        $id = $v;
    }
    //return embed iframe
    if($return == 'embed'){
        return '<iframe width="'.($width?$width:640).'" height="'.($height?$height:390).'" src="http://www.youtube.com/embed/'.$id.'?rel='.$rel.'" frameborder="0" allowfullscreen></iframe>';
    }
    //return normal thumb
    else if($return == 'thumb'){
        return 'http://i1.ytimg.com/vi/'.$id.'/default.jpg';
    }
    //return hqthumb
    else if($return == 'hqthumb'){
        return 'http://i1.ytimg.com/vi/'.$id.'/hqdefault.jpg';
    }
    // else return id
    else{
        return $id;
    }
}
 function rrmdir($dir) {
   if (is_dir($dir)) {
     $objects = scandir($dir);
     foreach ($objects as $object) {
       if ($object != "." && $object != "..") {
         if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
       }
     }
     reset($objects);
     rmdir($dir);
   }
 }
function tonum($string) {
	return number_format($string, 2, ".", " ");
}
?>